<?php

namespace app\common\controller;

use app\BaseController;

class AdminController extends BaseController
{

    // 服务
    protected $service;
    protected $param;
    protected $middleware = [
        'app\admin\middleware\TokenCheck',
        'app\admin\middleware\Auth'
    ];

    protected function initialize()
    {
        parent::initialize();
        $this->param = $this->request->param();
        $this->initConst();
    }
    private function initConst(){
        // 分页参数
        defined('PAGE') or define('PAGE', $this->request->param('page',1));
        defined('LIMIT') or define('LIMIT',$this->request->param('limit',10));
        define('IMG_URL', env('domain.img_url'));
    }
    public function getList(){
        $param = $this->request->param();
        $res = $this->service->getList($param);
        return success($res);
    }
    public function index(){
        $param = $this->request->param();
        $res = $this->service->getList($param);
        return success($res);
    }
    public function edit(){
        return $this->service->edit($this->param);

    }
    public function status(){
        $rule = [
            'id|ID'    => 'require',
            'status' => 'require',
        ];
        $this->validate($this->param, $rule);
        $this->service->status($this->param);
    }
    public function delete(){
        $this->service->delete($this->param);
        return success();
    }
}